﻿namespace Sidvall.WorkItemManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class MonitorExecutionContext : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.WorkItemManager.Data.IMonitorExecutionContext
    {
        #region Public Members

        #region MonitorExecutionContextId

        private System.Nullable<int> _MonitorExecutionContextId;
        partial void OnBeforeMonitorExecutionContextIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData);
        partial void OnAfterMonitorExecutionContextIdPropertyChanged();
        public System.Nullable<int> MonitorExecutionContextId
        { 
            get
            {
                return _MonitorExecutionContextId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _MonitorExecutionContextId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<int>>(value, _MonitorExecutionContextId);
                    OnBeforeMonitorExecutionContextIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("MonitorExecutionContextId", eventData.Value, true, true);
                        OnAfterMonitorExecutionContextIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorExecutionContextManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorExecutionContextManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public WorkItemAlarmCollectionItem WorkItemAlarms { get; set; }
        #region LoadWorkItemAlarms

        public void LoadWorkItemAlarms(WorkItemAlarmCollectionItem value)
        {
            LoadInstanceField("WorkItemAlarms", value, true, false);
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorExecutionContextManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public MonitorExecutionContext Copy()
        {
            return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorExecutionContextManager.Copy(this);
        }
        public MonitorExecutionContext Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorExecutionContextManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.WorkItemManager.Data.IMonitorExecutionContext item)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorExecutionContextManager.Import(this, item);
        }
        public void Import(global::Sidvall.WorkItemManager.Data.IMonitorExecutionContext item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorExecutionContextManager.Import(this, item, settings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorExecutionContextManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorExecutionContextManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorExecutionContextManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorExecutionContextManager.Initialize(this, settings);
        }

        #endregion

        #region IMonitorExecutionContext Members

        System.Nullable<int> global::Sidvall.WorkItemManager.Data.IMonitorExecutionContext.MonitorExecutionContextId
        {
            get
            {
                return this._MonitorExecutionContextId;
            }
            set
            {
                this._MonitorExecutionContextId = value;
            }
        }
        System.Collections.Generic.IEnumerable<global::Sidvall.WorkItemManager.Data.IWorkItemAlarm> global::Sidvall.WorkItemManager.Data.IMonitorExecutionContext.WorkItemAlarms
        {
            get
            {
                if (this.WorkItemAlarms != null)
                    return this.WorkItemAlarms.Items;
                return null;
            }
        }
        void global::Sidvall.WorkItemManager.Data.IMonitorExecutionContext.SetWorkItemAlarms(Sidvall.Data.IDataRowProvider<global::Sidvall.WorkItemManager.Data.IWorkItemAlarm> items)
        {
            this.WorkItemAlarms = (WorkItemAlarmCollectionItem)items;
        }

        #endregion

        #endregion
        #region Constructors

        public MonitorExecutionContext()
        {
        }
        public MonitorExecutionContext(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public MonitorExecutionContext(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitorExecutionContextManager.Initialize(this);
        }

        #endregion
    }
}